@startuml UC04_sequence
!theme plain
hide footbox
skinparam sequenceMessageAlign center
skinparam responseMessageBelowArrow true
skinparam BoxPadding 10
autonumber

title UC-04 - Avoid obstacle when right turn blocked\n(sequence diagram)

actor "Home user\n(beneficiary)" as User
participant "Obstacle sensors" as Obs
box "Roomba RVC control software\n(inside the SSD black box)" #E8F4FF
  participant "perception:\nObstaclePerceptionContext" as Perception
  participant "navigation:\nNavigationAndEscapeCoordinator" as Nav
  participant "cleaning:\nSurfaceCleaningController" as Clean
end box
participant "Wheel motors\n(left, right)" as Motors
participant "Cleaning hardware" as CleanHW

note over User, Clean : after UC-01; right not valid, left viable

Obs -> Perception : ObstacleStateChanged(forwardBlocked, rightBlocked)
Perception -> Nav : FusedObstacleSnapshot(rightTurnInvalid, leftTurnViable)
Nav -> Clean : SuspendCleaningForManeuver()
Clean -> CleanHW : CleaningCommand(suspend)

alt [typical right not valid turn left]
  Nav -> Motors : MotionCommand(turnLeft)
  Obs -> Perception : ObstacleStateChanged(forwardSafe)
  Perception -> Nav : FusedObstacleSnapshot(forwardSafe)
  Nav -> Motors : MotionCommand(forward)
  Nav -> Clean : ResumeCleaningAfterManeuver()
  Clean -> CleanHW : CleaningCommand(active)
  note over Nav, Motors : next: UC-02
else [A1 neither lateral viable]
  Nav -> Motors : MotionCommand(probeOrBackupTBD)
  note over Nav, Motors : may trend toward UC-05 (TBD)
else [E1 oscillation left and right]
  loop [debounce and maneuver limits TBD]
    Obs -> Perception : ObstacleStateChanged(oscillatingLateralReadings)
    Perception -> Nav : FusedObstacleSnapshot(unstable)
    Nav -> Motors : MotionCommand(suppressMotionTBD)
  end
end

@enduml
